package com.liner;

/**
 * Operator
 */
public class OperDemo {
    public static void main(String[] args) {
        /*
         * 算数运算符
         * */

        /*
        //单独使用：自增自减 放前放后都一样
        byte a1 = 127, b1 = -128;
        a1++;
        b1--;
        System.out.println(a1);
        System.out.println(b1);
        //被使用：自增自减 放前 先自增/减后赋值   放后 先赋值后自增/减
        //当被使用时：a++  ---> 值为a， ++a  ---> 值为a+1
        //当被使用时：a--  ---> 值为a， --a  ---> 值为a-1
        int a = 10;
        int b = 10;
        int c = a--; //c = 10 , a = 9
        int d = b-- + a++; //d = 19 , b = 9 , a = 10
        int e = --b + --a - d--; //b = 8 , a = 9 , d = 18 , e = 8 + 9 - 19 = -2
        int f = ++b + a-- + --d + c++ - e++; //f = 9 + 9 + 17 + 10 - -2 = 47

        System.out.println(a);//8
        System.out.println(b);//9
        System.out.println(c);//11
        System.out.println(d);//17
        System.out.println(e);//-1
        System.out.println(f);//47
*/

        /*
        关系运算符

        int a= 12,b = 13,c= 14;
        System.out.println(a>b);    //false
        System.out.println(a>=b);   //false
        System.out.println(a<b);    //true
        System.out.println(a<=b);   //true
        System.out.println(a==b);   //false
        System.out.println(a!=b);   //true
        System.out.println(a>c);    //false
        System.out.println(a++>c);  //a= 13 false
        System.out.println(a>=--c);  //a= 13 c = 13  true

        System.out.println(c--%12==0); //false
        System.out.println(c--%12==0); //true c = 12

        System.out.println(c++%12==0); //false c = 12
        System.out.println(--a + b++ == c*2); //a= 12,b = 14 c = 12 false
*/

        /*
         * 逻辑运算符
         *
        int a = 12, b = 34, c = 14;
        //短路与
        System.out.println(a >= c && a-- > b);
        System.out.println(a); //12
        //逻辑与
        System.out.println(a >= c & a-- > b);
        System.out.println(a);  //11

        //非
        if (!(a > b) || a++ < c) {
            System.out.println("这是真的");
            System.out.println(a);// 短路或 a = 11
        }


        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入年龄：");
        int age = scanner.nextInt();

        if (age < 0 || age > 300) {
            System.out.println("请输入正确的年龄");
        } else {

            if (age < 18) {
                System.out.println("你是未成年人");
            } else if (age < 40) {
                System.out.println("你是青年人");
            } else if (age <= 60) {
                System.out.println("你是中年人");
            } else {
                System.out.println("你是老年人");
            }
        }
*/

        /*
         * 赋值运算符
         *
        int a = 10;
        a += 12;
        System.out.println(a); //10 + 12 = 22
        a -= 20;
        System.out.println(a); //22 - 20 = 2
        a *= 6;
        System.out.println(a); //2 * 6 = 12
        a /= 2;
        System.out.println(a); //12 / 2 = 6
        a %= 2;
        System.out.println(a); //6 % 2 = 0


        //小面试题
        byte b = 12;
        b -= 10;        //扩展赋值符自带前置类型转换  b-=10 ---> b = (byte)(b-10);
        //b = b-10;    //当 byte、short、char进行运算时会自动转换成int类型再运算
        System.out.println(b); // 2
*/



        /*
         *
         * 字符串连接运算符
         *

        System.out.println('我' + '你'); //进行算数运算   45425
        System.out.println("我" + "你");    //进行字符拼接  我你

        String name = "一只耳";
        String name2 = "黑猫警长";
        System.out.println("大家好，我叫" + name + "，我在寻找" + name2 + ",我知道他找不到我");

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入年龄：");
        int age = scanner.nextInt();

        System.out.println("这个人的年龄是:" + age);

        //不管什么数据类型，和String连接其结果都是字符串型
        int a = 123;
        System.out.println(a+12+"" + 23); //13523
        System.out.println(a+"" + 123);  //123123


        System.out.println(10 + 20 + 30 + "" + 120 + 123); //60120123
        System.out.println(10 + "" + 20 + 30 + 120 + 123); //102030120123
        System.out.println(10 + 20 + 30 + 120 + 123 + ""); //303
 */

        /*
         *
         * 条件运算符
         * */


        int a = 12, b = 14;
        System.out.println(a > b ? "最大值为a:" + a : "最大值为b:" + b);

        int max = a>b ? a : b;
        System.out.println(max);




    }
}
